home *** CD-ROM | disk | FTP | other *** search
/ Hyper Stacks 1994 May / Hyper Stacks (Pacific HiTech)(1994)[Mac].iso / HyperTalk / AppleTalk Toolkit v.2.5 / ATP / ATPSendRequest.c < prev   
Encoding:
C/C++ Source or Header  |  1988-06-15  |  5.9 KB  |  205 lines  |  [TEXT/MPS ]

  1. /*******************************************************************\
  2. *    file:         ATPSendRequest.c                                    *
  3. *    version:    1.06ß                                                *
  4. *                                                                     *
  5. * Send a message to the listener whose entity name is provided by     *
  6. * caller.                                                            *
  7. * -----------------------------------------------------------------    *
  8. * By:    Donald Koscheka, Greg Kimberly                                *
  9. * By:    Greg Kimberly, Donald Koscheka                                *
  10. * Date:    24-Sept-87                                                    *
  11. * ©    Copyright 1987, Apple Computer, Inc.                            *
  12. *    All Rights Reserved                                                *
  13. *                                                                    *
  14. * -----------------------------------------------------------------    *
  15. *                        Modification History                        *
  16. * -----------------------------------------------------------------    *
  17. *  Date           | By    |                     Description                    *
  18. * -----------------------------------------------------------------    *
  19. * 9/24/87    | GK    | file created                                    *
  20. * 10/6/87    | DK    | added retry count and interval as parameters.    *
  21. *  5-Nov-87    | DK    | added return result                            *
  22. *  3-Dec-87    | DK    | check to see whether node is a client and     *
  23. *            |        | terminate if not                                *
  24. *  7-Dec-87    | DK    | removed the confirm before each request.        *
  25. * 11-Dec-87    | DK    | Set default retry count to 0.                    *
  26. *            |        | Don't send if no message specified...            *
  27. * 21-Dec-87    | DK    | set response method to nil if not used        *
  28. * 14-Jan-88    | DK    | modified to reflect decoupling of ATP & NBP    *
  29. * 22-Feb-88 | DK    | Move all locked handles high                    *
  30. * -----------------------------------------------------------------    *
  31. \*******************************************************************/
  32.  
  33. /*******************************************************************\
  34.                             Build Sequence
  35.     
  36. C -q2 -g -o "{hpo}"ATPSendRequest.c.o "{atp}"ATPSendRequest.c
  37.     link  -sn Main=ATPSendRequest -sn STDIO=ATPSendRequest ∂
  38.          -sn INTENV=ATPSendRequest -rt XCMD=306 ∂
  39.          -m ATPSENDREQUEST ∂
  40.          "{hpo}"ATPSendRequest.c.o "{hpo}"atalkxcmd.c.o "{hpo}"xcmdutils.c.o ∂
  41.          "{CLibraries}"CInterface.o ∂
  42.          "{Libraries}"Interface.o ∂
  43.          -o "{hp}"HyperPeople
  44.  
  45. \*******************************************************************/
  46.  
  47. #include <Types.h>
  48. #include <Memory.h>
  49. #include <Resources.h>
  50. #include <OSUtils.h>
  51. #include <appleTalk.h>
  52. #include <HyperXCmd.h>
  53. #include <atalkXCMD.h>
  54. #include <XCMDUtils.h>
  55.  
  56. char *GetNextName();
  57.  
  58.  
  59. pascal void ATPSendRequest( paramPtr )
  60.     XCmdBlockPtr    paramPtr;
  61. /**********************************
  62. * ATRequest - send a request to the 
  63. * node specified by entityName.  If a 
  64. * response message is given, the response
  65. * data is appended to it and hypercard is 
  66. * called back with the response.
  67. *
  68. * In:    ParamPtr->params[0] = list of names to send to
  69. *        ParamPtr->params[1] = message
  70. *        ParamPtr->params[2] = response message 
  71. *        ParamPtr->params[3] = number of retries
  72. *        ParamPtr->params[4] = interval between retries
  73. *
  74. * Out:    Request message sent asynchronously 
  75. *        to the server
  76. *
  77. **********************************/
  78. {
  79.     ATPBlock    *atp;
  80.     NBPBlock    *nbp;
  81.     short        nextentity     = 1;
  82.     short        found         = 0;
  83.     short        c, intv;
  84.     short        result;
  85.     short        mlen;
  86.     char        *theData; 
  87.     Handle        rmess        = nil;
  88.     char         str[32];
  89.     char        *currentName, *nextName;
  90.     EntityName     eName;
  91.     AddrBlock     eAddr;    
  92.     
  93.     atp = (ATPBlock *)RetrieveHandle( paramPtr, GLOBALATPDATA );
  94.     nbp = (NBPBlock *)RetrieveHandle( paramPtr, GLOBALNBPDATA );
  95.  
  96.     if( !atp || !nbp ){
  97.         paramPtr->returnValue = ErrorReturn( DEFAULT_ERROR );
  98.         return;
  99.     }
  100.     
  101.     if( !atp->Client ){
  102.         paramPtr->returnValue = ErrorReturn( DEFAULT_ERROR );
  103.         return;
  104.     }
  105.     
  106.     if( !paramPtr->params[ 0 ] ){
  107.         paramPtr->returnValue = ErrorReturn( DEFAULT_ERROR );
  108.         return;
  109.     }
  110.     
  111.     if( paramPtr->params[ 1 ] )        /*** was a message specified ??? ***/
  112.         mlen = slength(*(paramPtr->params[1]) );
  113.     else{
  114.         paramPtr->returnValue = ErrorReturn( DEFAULT_ERROR );
  115.         return;
  116.     }
  117.     
  118.     MoveHHi( paramPtr->params[0] );
  119.     HLock( paramPtr->params[0] );
  120.  
  121.     if( paramPtr->params[2] != nil ){
  122.         rmess = paramPtr->params[2];
  123.         if( !**rmess )
  124.             rmess = nil;                /*** treat empties as nils                ***/
  125.     }
  126.         
  127.     if( paramPtr->params[3] != nil ){
  128.         MoveHHi( paramPtr->params[3] );
  129.         HLock( paramPtr->params[3] );
  130.         c2pstr( *(paramPtr->params[3] ));
  131.         c = (short)StrToNum( paramPtr, *(paramPtr->params[3]) );
  132.         HUnlock( paramPtr->params[3] );
  133.     }
  134.     else
  135.         c = 0;    
  136.     
  137.     if( paramPtr->params[4] != nil ){
  138.         MoveHHi( paramPtr->params[4] );
  139.         HLock( paramPtr->params[4] );
  140.         c2pstr( *(paramPtr->params[4] ));    
  141.         intv = (short)StrToNum( paramPtr, *(paramPtr->params[4]) );
  142.         HUnlock( paramPtr->params[4] );
  143.     }
  144.     else
  145.         intv = 0;
  146.  
  147.     nextName = *(paramPtr->params[0]);    /*** point to the first name in  list     ***/
  148.     while( currentName = nextName ){    /*** repeat for all names in the list     ***/        
  149.         nextName = GetNextName( nextName );
  150.         found = 0;
  151.         nextentity = 1;
  152.         /*** scan names list until we find a match or scan past all entities.    ***/
  153.         while( !found ){
  154.              found = ExtractName( nbp, nextentity, &eName, &eAddr );
  155.              if( found == 1 ){
  156.                  pStrCopy( &(eName.objStr), str ); /*** need to keep tuple intact***/
  157.                 p2cstr( str );
  158.                 if( !strCMP(  currentName , str ) ){
  159.                     MoveHHi( paramPtr->params[1] );
  160.                     HLock( paramPtr->params[1] );
  161.                     theData = *(paramPtr->params[1]);
  162.                     currentName = (char *)str;
  163.  
  164.                     result = Request( atp, theData, mlen, &eAddr, rmess,c, intv );
  165.                     HUnlock( paramPtr->params[1] );
  166.                 }
  167.                 else{
  168.                     found = 0;
  169.                     ++nextentity;
  170.                 }
  171.             }
  172.         } 
  173.     } /*** while nextName ***/
  174.     
  175.     HUnlock( paramPtr->params[0] );
  176.     paramPtr->returnValue = ErrorReturn( result );
  177. }
  178.  
  179.  
  180. char *GetNextName( theList )
  181.     char    *theList;
  182. /****************************
  183. * Given a pointer to a list of \r 
  184. * terminated names, replace the terminator
  185. * with \0 and point to the character after
  186. * the last \r found (leapfrog string).
  187. *
  188. * returns nil when last name is found.
  189. *
  190. ***************************/
  191. {    
  192.     if( *theList == '\0' )
  193.         return( nil );
  194.  
  195.     while( ( *theList != '\n' ) && ( *theList != '\0' ) )
  196.         theList++;
  197.  
  198.     if( *theList == '\n' ){
  199.         *theList = '\0';
  200.         ++theList;        /*** move to next string in the list     ***/
  201.         return( theList );
  202.     }
  203. }
  204.  
  205.